import { IEventEmitter, IAppEvent, IMediator } from "../interfaces";


export class EventEmitter implements IEventEmitter {
    protected _mediator: IMediator;
    protected _events: IAppEvent[]

    constructor(mediator: IMediator) {
        this._mediator = mediator;
    }

    triggerEvent(topic: string, data: any): void {
        this._mediator.publish(topic, data)
    }
    subscribeEvents(events: IAppEvent[]): void {
        this._events = events;
        for (let index = 0; index < this._events.length; index++) {
            this._mediator.subscribe(this._events[index])
        }
    }
    unsubscribeToEvents(): void {
        for (let index = 0; index < this._events.length; index++) {
            this._mediator.unsubscribe(this._events[index])
        }
    }


}